package com.aaa.moneymanage.services.impl;

import com.aaa.entity.OrderBackfee;
import com.aaa.entity.OrderBackfeeItem;
import com.aaa.moneymanage.dao.MoneyoutDao;
import com.aaa.moneymanage.dao.OrderBackfeeItemDao;
import com.aaa.moneymanage.services.MoneyoutServices;
import com.aaa.moneymanage.vo.MoneyVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：XiaoxXuan
 * @date ：Created in 2023/3/22 17:09
 * @description：
 * @modified By：
 */
@Service
public class MoneyoutServicesImpl implements MoneyoutServices {

    @Resource
    private MoneyoutDao moneyoutDao;

    @Resource
    private OrderBackfeeItemDao orderBackfeeItemDao;

    /** * @create by: XiaoXuan
     * @description: 退费列表查询所有 
     * @create time: 2023/4/7 20:03
     * * @param currentPage
     * @param pageSize
     * @param moneyVo 
     * @return com.aaa.vo.Result<com.baomidou.mybatisplus.core.metadata.IPage < com.aaa.entity.OrderBackfee>> 
     */
    @Override
    public Result<IPage<OrderBackfee>> getMoneyIn(Integer currentPage, Integer pageSize, MoneyVo moneyVo) {

        IPage<OrderBackfee> page=new Page<>(currentPage,pageSize);

        QueryWrapper<OrderBackfee> wrapper=new QueryWrapper<>();
        if(StringUtils.hasText(moneyVo.getPatientName())){
            wrapper.like("patient_name",moneyVo.getPatientName());
        }
        if(StringUtils.hasText(moneyVo.getRegId())){
            wrapper.eq("reg_id",moneyVo.getRegId());
        }
        IPage<OrderBackfee> orderBackfeeIPage = moneyoutDao.selectPage(page, wrapper);
        return new Result<IPage<OrderBackfee>>(200,"查询退费管理成功",orderBackfeeIPage);


    }

    /** * @create by: XiaoXuan
     * @description: 退费列表查看详情 
     * @create time: 2023/4/7 20:04
     * * @param backId 
     * @return com.aaa.vo.Result<java.util.List < com.aaa.entity.OrderBackfeeItem>> 
     */
    @Override
    public Result<List<OrderBackfeeItem>> selectOneByOrderId(String backId) {
        QueryWrapper<OrderBackfeeItem> wrapper = new QueryWrapper<>();
        wrapper.eq("back_id",backId);
        List<OrderBackfeeItem> orderBackfeeItems = orderBackfeeItemDao.selectList(wrapper);
        return new Result<>(200,"查询支付订单成功",orderBackfeeItems);
    }

    /** * @create by: XiaoXuan
     * @description:  插入退费列表的方法（数据库添加）
     * @create time: 2023/4/7 20:05
     * * @param orderBackfee 
     * @return boolean 
     */
    @Override
    public boolean insertOrderBackfee(OrderBackfee orderBackfee) {
        return moneyoutDao.insertBackfeeCharge(orderBackfee);

    }

    /** * @create by: XiaoXuan
     * @description: 插入退费列表查看详情表的方法 
     * @create time: 2023/4/7 20:06
     * * @param orderBackfeeItem 
     * @return boolean 
     */
    @Override
    public boolean insertOrderBackfeeItem(OrderBackfeeItem orderBackfeeItem) {
        return orderBackfeeItemDao.insertOrderBackfeeItem(orderBackfeeItem);
    }
}